package santiago.domain;

import java.awt.Color;
import java.io.Serializable;

public enum ColorType implements Serializable {

    WHITE(new Color(189, 188, 188), new Color(189, 188, 188)),
    BEIGE(new Color(213, 173, 104), new Color(213, 173, 104)),
    PURPLE(new Color(130, 35, 41), new Color(130, 35, 41)),
    GRAY(new Color(112, 95, 65), new Color(112, 95, 65)),
    BLACK(new Color(59, 59, 59), new Color(59, 59, 59));
    private Color Color;
    private Color Precinct;

    private ColorType(Color Color, Color Precinct) {
        this.Color = Color;
        this.Precinct = Precinct;
    }

    public Color getColor() {
        return Color;
    }

    public Color getPrecinctColor() {
        return Precinct;
    }

    public static Color getColor(String ColorName) {
        Color Col;
        switch (ColorName) {
            case "WHITE":
                Col = WHITE.getColor();
                break;
            case "BEIGE":
                Col = BEIGE.getColor();
                break;
            case "PURPLE":
                Col = PURPLE.getColor();
                break;
            case "GRAY":
                Col = GRAY.getColor();
                break;
            case "BLACK":
                Col = BLACK.getColor();
                break;
            default:
                Col = null;
        }
        return Col;
    }

    /**
     * Returns a string like #4F0E8D corresponding to the rgb hex representation
     * of the color
     *
     * @return hexadecimal representation RGB CSS compliant
     */
    public String toCSSColor() {
        StringBuilder b = new StringBuilder("#");
        if (Color.getRed() <= 15) {
            b.append("0");
        }
        b.append(Integer.toHexString(Color.getRed()));
        if (Color.getGreen() <= 15) {
            b.append("0");
        }
        b.append(Integer.toHexString(Color.getGreen()));
        if (Color.getBlue() <= 15) {
            b.append("0");
        }
        b.append(Integer.toHexString(Color.getBlue()));
        return b.toString();
    }
}
